package lesson.tcp.test2;

import java.io.*;
import java.net.Socket;

public class ClientDemo {
    public static void main(String[] args) throws IOException {
        //1.创建一个Socket对象
        Socket socket = new Socket("127.0.0.1",10000);

        //2.获取一个IO流开始写数据
        OutputStream outputStream = socket.getOutputStream();
        outputStream.write("HelloWorld！".getBytes());
        socket.shutdownOutput();


        //获取服务器返回数据
        InputStream is = socket.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        String line;
        while ((line = br.readLine())!= null){
            System.out.println("收到服务器信息，为："+line);
        }

        //3.释放资源
        br.close();
        outputStream.close();
        socket.close();
    }
}
